#ifndef _COMPLEX_CUBIC_H
#define _COMPLEX_CUBIC_H

#include "icell.h"

#include <vector>

// ===============================================================
//  Déclaration de la classe complexe cubique : ComplexCubic
// ===============================================================

template<int t_iDimComp, int t_iDimPoint, typename t_Type>
class ComplexCubic
{
	public:
		ComplexCubic() {}
		~ComplexCubic() {}
		
		bool IsValid();
		std::vector<VirtualICell*>::iterator FindICell(VirtualICell* p_picCell, int p_iDim);
		
		//void FillComplexes(VirtualICell* p_picICell, int p_iDim);
		//void Display();
		
	private:
		std::vector<VirtualICell*> m_vComplexes[t_iDimComp + 1];
		
};

// ===============================================================
//  Implantation des fonctions membres.
// ===============================================================

template<int t_iDimComp, int t_iDimPoint, typename t_Type>
bool ComplexCubic<t_iDimComp, t_iDimPoint, t_Type>::IsValid()
{
	for (int i = 0; i <= t_iDimComp; i++)
	{
		int iNbBorderCells = 2 * (t_iDimComp - i);
		if (iNbBorderCells > 0)
		{
			std::vector<VirtualICell*>::iterator it = m_vComplexes[i].begin();
			for (it = m_vComplexes[i].begin(); it != m_vComplexes[i].end(); ++it)
			{
				const VirtualICell** picBorderCells = (*it)->GetBorderCells();
				for (int j = 0; j < iNbBorderCells; i++)
				{
					//if (picBorderCells[j] == NULL)
						//return false;
				}
			}
		}
	}
	return true;
}

// ---------------------------------------------------------------
template<int t_iDimComp, int t_iDimPoint, typename t_Type>
std::vector<VirtualICell*>::iterator ComplexCubic<t_iDimComp, t_iDimPoint, t_Type>::FindICell(VirtualICell* p_picCell, int p_iDim)
{
	int iPosComplexes = t_iDimComp - p_iDim;
	std::vector<VirtualICell*>::iterator it = m_vComplexes[iPosComplexes].begin();
	for (it = m_vComplexes[iPosComplexes].begin(); it != m_vComplexes[iPosComplexes].end(); ++it)
	{
		if (*it == p_picCell)
			return it;
	}
	return it;
}















/*template<int t_iDimComp, int t_iDimPoint, typename t_Type>
ComplexCubic<t_iDimComp, t_iDimPoint, t_Type>::ComplexCubic()
{
	ICell<t_iDimComp, t_iDimPoint, t_Type>* picCell = new ICell<t_iDimComp, t_iDimPoint, t_Type>();
	if (picCell != NULL)
		FillComplexes(picCell, t_iDimComp);
}*/

// ---------------------------------------------------------------
/*template<int t_iDimComp, int t_iDimPoint, typename t_Type>
void ComplexCubic<t_iDimComp, t_iDimPoint, t_Type>::FillComplexes(VirtualICell* p_picICell, int p_iDim)
{
	std::cout << "I - Debut FillComplexes" << std::endl;
	m_vComplexes[t_iDimComp - p_iDim].push_back(p_picICell);
	
	std::cout << "II - Milieu FillComplexes" << std::endl;
	//VirtualICell* picBorderCells;
	ICell<1 , t_iDimPoint, t_Type>picBorderCells;
	std::cout << "prout 1" << std::endl;
	if (p_iDim > 0)
	{
		/*std::cout << "prout 2" << std::endl;
		if (p_picICell->GetBorderCells() == NULL) {
			std::cout << "les border cells sont nulles" << std::endl;
		}*/
		//picBorderCells = const_cast<VirtualICell*>(p_picICell->GetBorderCells());
		/*for (int i = 0; i < 2 * p_iDim; i++)
			std::cout << picBorderCells[i].Display();
		std::cout << "prout 3" << std::endl;*/
	/*}
	
	std::cout << "dimension : " << p_iDim << std::endl;
	for (int i = 0; i < 2 * p_iDim; i++)
	{
		std::cout<<"etape "<< i <<", dimension " << p_iDim << " debut"<<std::endl;
		//m_vComplexes[t_iDimComp - p_iDim + 1].push_back(&picBorderCells[i]);
		//if (p_iDim > 0)
		if (&picBorderCells[i] == NULL)
			std::cout << "c'est null dégage !" << std::endl;
		FillComplexes(&picBorderCells[i], p_iDim - 1);
		
		std::cout<<"etape "<< i <<", dimension " << p_iDim << " fin" << std::endl;
	}
	std::cout << "III - Fin FillComplexes" << std::endl;
}*/


// ---------------------------------------------------------------
/*template<int t_iDimComp, int t_iDimPoint, typename t_Type>
void ComplexCubic<t_iDimComp, t_iDimPoint, t_Type>::Display()
{
	for (int i = 0; i <= t_iDimComp; i++)
	{
		
	}
}*/

#endif // _COMPLEX_CUBIC_H
